package GameLogic
{
	import DataStore.BmpDataPool;
	import fl.controls.Button;
	import fl.controls.TextArea;
	import fl.controls.TextInput;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.utils.Dictionary;

	public class LuaEditer extends Sprite
	{
		public  var Hide:Boolean = true;
		public  var Pos:Point = new Point(0,0);
		public  var btn:Button;
		public  var runImgBtn:SpriteBtn;
		public  var clearImgBtn:SpriteBtn;
		public  var traceImgBtn:SpriteBtn;
		public  var closeImgBtn:SpriteBtn;
		public  var LuaEditBtn:SpriteBtn;
		public  var input:TextArea;
		
		public  var OutputWin:TextArea;
		
		
		public function LuaEditer()
		{
			Init();
			Game.MenuCanvas.addChild(this);
		}
		
		public  function Init():void
		{
			this.x = 760 - 352;
			this.y = 560 - 426;
			this.alpha = 0.9;
			Delay();
		}
		
		private function Delay():void
		{
			var boderLeft:Bitmap = new Bitmap(BmpDataPool.LuaEditorPool[105]);
			this.addChild(boderLeft);
			boderLeft.x = 0;
			boderLeft.y = 0;
			
			var boderTop1:Bitmap = new Bitmap(BmpDataPool.LuaEditorPool[106]);
			this.addChild(boderTop1);
			boderTop1.x = 57;
			boderTop1.y = 0;

			var boderBottom1:Bitmap = new Bitmap(BmpDataPool.LuaEditorPool[107]);
			this.addChild(boderBottom1);
			boderBottom1.x = 57;
			boderBottom1.y = 407;
			
			input = new TextArea();
			this.addChild(input);
			input.x = 63;
			input.y = 18;
			input.width = 285;
			input.height = 390;
			
			var closeImgBtn:Sprite =  new Sprite();
			var temp:Bitmap = new Bitmap(BmpDataPool.LuaEditorPool[109]);
			temp.x = -5;
			temp.y = -5;
			closeImgBtn.addChild(temp);
			this.addChild(closeImgBtn);
			closeImgBtn.addEventListener(MouseEvent.CLICK, function(e:Event):void
			{
				Game.LuaEdit.visible = false;
			});
			closeImgBtn.addEventListener(MouseEvent.MOUSE_OVER, function(e:Event):void
			{
				closeImgBtn.scaleX = 1.1;
				closeImgBtn.scaleY = 1.1;
			});
			closeImgBtn.addEventListener(MouseEvent.MOUSE_OUT, function(e:Event):void
			{
				closeImgBtn.scaleX = 1;
				closeImgBtn.scaleY = 1;
			});
			var runImgBtn:SpriteBtn =  new SpriteBtn(BmpDataPool.LuaEditorPool[115]);
			this.addChild(runImgBtn);
			runImgBtn.addEventListener(MouseEvent.CLICK, function(e:Event):void
			{
				DoLuaScript();
			});
			runImgBtn.x = -20;
			runImgBtn.y = 60;
			var clearImgBtn:SpriteBtn =  new SpriteBtn(BmpDataPool.LuaEditorPool[108]);
			this.addChild(clearImgBtn);
			clearImgBtn.addEventListener(MouseEvent.CLICK, function(e:Event):void
			{
				OutputWin.text = "";
			});
			clearImgBtn.x = -20;
			clearImgBtn.y = 100;
			
			var traceImgBtn:SpriteBtn =  new SpriteBtn(BmpDataPool.LuaEditorPool[114]);
			this.addChild(traceImgBtn);
			traceImgBtn.addEventListener(MouseEvent.CLICK, function(e:Event):void
			{
				if (!OutputWin.visible)
				{
				   OutputWin.visible = true;
				   OutputWin.alpha = 0.9;
				   setChildIndex(OutputWin, 0);
				}
				else
				{
					OutputWin.visible = false;
				}
			});
			traceImgBtn.x = -20;
			traceImgBtn.y = 140;
			
			OutputWin = new TextArea();
			OutputWin.width = 235;
			OutputWin.height = 306;
			OutputWin.x = -256;
			OutputWin.y = 76;
			this.addChild(OutputWin);
			OutputWin.visible = false;		
			OutputWin.editable = false;
		}
		
		private function DoLuaScript():void
		{
			try
			{
			    Game.LuaAl.doString(input.text);
			}
			catch (e:Error)
			{
				trace(e.message);
			}
		}
	}
}